#define _GNU_SOURCE // 如是不声明gettid()不识别报错
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

void *first_thread(void *arg){
    printf("first_thread线程启动（first_thread tid: %d） \n",gettid());

    return NULL;
}

void *second_thread(void *arg){
    printf("second_thread线程启动（second_thread tid: %d） \n",gettid());

    return NULL;
}

int main(int argc, char const *argv[])
{
    printf("main线程启动（main tid: %d） \n",gettid());

    // 创建线程
    pthread_t td1, td2;
    pthread_create(&td1, NULL, first_thread, NULL);
    pthread_create(&td2, NULL, second_thread, NULL);

    printf("main线程继续执行，td1: %ld, td2: %ld \n", td1, td2);

    // 等待线程结束
    pthread_join(td1, NULL);
    pthread_join(td2, NULL);

    printf("main线程结束 \n");

    return 0;
}
